import urlConfig from './config.js'
const request = {}
const headers = {}
const PORT1 = '/baseinfo'
let cookies = ''

request.globalRequest = (url, method, data, power) => {
	headers['Device-Type'] = uni.getSystemInfoSync().platform;
	headers['content-type'] = 'application/x-www-form-urlencoded';
	
	headers['openid'] = uni.getStorageSync('openid');
	
	return uni.request({
		url: urlConfig + url,
		method,
		data: data,
		dataType: 'json',
		header: headers
	}).then(res => {
		console.log(JSON.stringify(res))
		if (res[1].data.state && res[1].data.state == 200) {
			return res[1]
		} else {
			throw res[1].data
		}
	}).catch(parmas => {
		console.log(parmas)
		switch (parmas.code) {
			case 401:
				uni.clearStorageSync()
				break
			default:
				uni.showToast({
					title: parmas.message,
					icon: 'none'
				})
				return Promise.reject()
				break
		}

	})
};
export default request
